package com.foreknow.springboot_demo.controller;

import com.foreknow.springboot_demo.model.Admin;
import com.foreknow.springboot_demo.service.AdminService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/admin")
public class AdminController {
    @Autowired
    private AdminService adminService;

    @RequestMapping("index")
    public ModelAndView page1() {
        return new ModelAndView("/index.html") ;
    }

    @RequestMapping("map")
    public Map<String, String>  map1() {
        Map<String, String> map = new HashMap<String, String>();
        map.put("name", "张三");
        map.put("age", "28");
        return map;
    }
    @GetMapping("/login")
    public Admin login(Admin admin, ModelMap modelMap) {
        Admin admin1 = adminService.findByNameAndPassword(admin);
        modelMap.addAttribute("username",admin1.getUserName());
        modelMap.addAttribute("password",admin1.getPassword());
        return admin1;
    }
}
